<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	StringBuffer strURL = request.getRequestURL();
	String URL = strURL.toString();
	String contPath = request.getContextPath();
	int nIndex = URL.indexOf(contPath);
	URL = "http://tugo.cn/weixin_aef/";
	%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="<%=URL%>newedition/css/aui.css" />
<link rel="stylesheet"
	href="<%=URL%>newedition/css/oiler_login.css" />
<script type="text/javascript"
	src="<%=URL%>newedition/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/getVerifyCode.js"></script>
<script type="text/javascript"
	src="<%=URL%>newedition/js/aui-toast.js"></script>
<script type="text/javascript" src="<%=URL%>js/base64.js"></script>
<script type="text/javascript" src="<%=URL%>newedition/js/base.js?version=4.0"></script>
<script type="text/javascript" src="<%=URL%>js/cookies.js?version=1.1"></script>
<script type="text/javascript" src="<%=URL%>newedition/js/auipopupstyle.js"></script>
<title>收油商-登录界面</title>
<style>
.unlabed {
	background-color: #C8C8C8 !important;
}
</style>
</head>
<body>
<input type=hidden name=contextPath value=<%= request.getContextPath()%> id="requestpath"> 
	<div class="banner-box">
		<img src="<%=URL%>newedition/img/oiler_login_img.png" />
		<div class="banner-title aui-margin-t-15">
			<span>收油商</span>
		</div>
	</div>
	<div class="login-form aui-padded-15">
		<div class="form-header aui-margin-b-15">
			<img src=""  id="heard"/>
		</div>
		<div class="form-phone aui-margin-b-15">
			<span>手机：</span> <input type="tel" id="mobile" />
		</div>
		<div class="form-pass">
			<input type="text" id="captchanum" /> <span id="captchanumspan" onclick="getcaptcha()">发送验证码</span>
		</div>
	</div>
	<div
		class="form-submit aui-btn aui-btn-warning aui-btn-block aui-btn-outlined aui-btn-sm aui-margin-b-15"
		onclick="login()">确认</div>
	<div class="form-ps">
		<span></span>手机绑定后才能登录
	</div>
</body>
<script type="text/javascript">
		$(function(){
			GetSingleOpenId(getCookie("openid"))   
		})
		/**
 * 获取验证码
 */
var count = 60;
function getcaptcha() {
	showDefault("loading","加载中...");
	var mobile = $("#mobile").val();
	var json = {}
	if(count==60){
		if(!mobile.match(/^1[34578]\d{9}$/)) {
			toast.hide();
			showDefault("fail","输入有效的手机号");
		}else{
			if(getCookie("roleId")=="9"||!getCookie("roleId")||getCookie("roleId")=="undefined"||getCookie("roleId")=="null"){
				var data= httpget(''+httpipstr+'alfa-mobile-ws/rest/user/getCaptchaForWorker/' + mobile + '');
				toast.hide();
				if (data.status == "failure") {
					if(data.message=="4"){
						showDefault("fail","手机号不存在");
					}if(data.message=="3"){
						showDefault("fail","角色非收运人员,不能获取手机验证码");
					}if(data.message=="1"){
						showDefault("fail","角色收运人员,不能获取手机验证码");
					}
				} else {
					var countdown = setInterval(CountDown, 1000);
					function CountDown() {
						$("#captchanumspan").addClass("unlabed"); //将DIV标签隐藏。
						$("#captchanumspan").html("重新发送(" + count + ")");
						if (count == 0) {
							$("#captchanumspan").removeClass("unlabed"); //将DIV标签隐藏。
							$("#captchanumspan").html("发送验证码");
							clearInterval(countdown);
						}
						count--;
					}
				}
			}else{
				toast.hide();
				showDefault("fail","产废角色已登录，无法再次登录");
			}
			
			
		}
	}else{}
	
}

/**
 * 登录
 */
function login() {
	showDefault("loading","登录中...");
	var mobile = encode64($("#mobile").val());
	var captchanum = encode64($("#captchanum").val());
	var json = {
		"mobile": "" + mobile + "",
		"captcha": "" + captchanum + "",
		"openid":""+getCookie("openid")+"",
		"logintype":""+encode64("9")+""
	}
	if(getCookie("roleId")=="9"||!getCookie("roleId")||getCookie("roleId")=="undefined"||getCookie("roleId")=="null"){
		$.ajax({
			cache: false,
			type: "post",
			datatype: 'json',
			contentType: 'application/json;charset=UTF-8',
			url: ''+httpipstr+'alfa-mobile-ws/rest/user/loginforweixin',
			data: JSON.stringify(json),
			success: function(data) {
				toast.hide();
				if (data.message=="7") {
				
					if(data.data.roleId=="9"){
						setcookie("mobiletokensalesman", data.data.mobiletoken, 300, "/");
						setcookie("username", data.data.username, 300, "/");
						setcookie("salesmaniphone", data.data.phone, 300, "/");
							//触发事件
						location.href="oiler_taskList.jsp"
					}else{
						showDefault("fail","您的角色不正确，无法登录");
					}

					
				} else {
					if(data.message=="1"){
						showDefault("fail","服务器异常，请联系管理员。");
					} if(data.message=="2"){
						showDefault("fail","请输入手机号和验证码。");
					} if(data.message=="3"){
						showDefault("fail","验证码不正确。");
					} if(data.message=="4"){
						showDefault("fail","验证码已经超过有效时间。");
					} if(data.message=="5"){
						showDefault("fail","帐号不存在");
					}
					 if(data.message=="15"){
						 showDefault("fail","您的角色不正确，无法登录");
						
					}
				}

			}
		});
	}else{
		toast.hide();
		 showDefault("fail","产废角色已登录，无法再次登录");
	}

}
		</script>
</html>
